%div.container-fluid
  %div.row
    %div.col-lg-12
      %div.col-lg-12{:style=>" max-width:700px;"}
        %h3{:style => "padding-left:3px;"}
          Generated Binary
        %br

        -device = nil

        .well.well-lg{:style=>" max-width:700px;"}

          %h5 Generation Configuration
          - params.to_a.each do |p|
            - if p[0].include? "section"
              - sect_id = p[0].gsub("section_","")
              - s = Section.find(sect_id)
              - c = Capture.find(p[1])
              - d = device = c.unit.device
              %p{:style=>" max-width:500px; word-wrap:break-word;"}
                %span= "Section: "
                %span{:style=>" color:white;"}= "#{s.name} "
                %span= "(bits #{s.start_pos} to #{s.end_pos})"
                %span= "from: "
                %span{:style=>" color:white;"}= "#{c.unit.name}" 
                %span= " - "
                %span{:style=>" color:white;"}= "#{c.name}"
                 
          %br
        .well.well-lg{:style=>" max-width:700px;"}
          %h4 Original Format
          %br
          %h5 Binary 
          -bin = ""
          -type = ""
          - params.to_a.each do |p|
            - if p[0].include? "section"
              - sect_id = p[0].gsub("section_","")
              - s = Section.find(sect_id)
              - c = Capture.find(p[1])
              - d = c.unit.device
              - device = d
              // CHECK MODULATION
              - if d.could_be_pwm_7525?
                - type = "pwm7525"
                - b = c.pwm_decode_7525
                - bin << b[s.start_pos..s.end_pos]
              - elsif d.could_be_pwm?
                - type = "pwm"
                - b = c.pwm_decode
                - bin << b[s.start_pos..s.end_pos]
              - elsif d.could_be_manchester?
                - type = "manchester"
                - b = c.manchester_decode
                - bin << b[s.start_pos..s.end_pos]
              - else 
                - type = "ook"
                - b = c.original_binary
                - bin << b[s.start_pos..s.end_pos]
          %p{:style=>" max-width:500px; word-wrap:break-word;"}=bin
          %br
          %span="Size: "
          %span= bin.size
          %span="bits "
          %br
          %br

        .well.well-lg{:style=>" max-width:700px;"}
          %h4  OOK Format 
          %br
          %h5 Binary
          - ook_bin = ""
          // CHECK MODULATION
          - if device.flip_pwm
            - if type == "pwm7525"
              -bin.scan(/./).each do |bit|
                - ook_bin << "1000" if bit.to_s == '1'
                - ook_bin << "1110" if bit.to_s == '0'
            - elsif type == "pwm"
              -bin.scan(/./).each do |bit|
                - ook_bin << "100" if bit.to_s == '1'
                - ook_bin << "110" if bit.to_s == '0'
            - elsif type == "manchester"
              -bin.scan(/./).each do |bit|
                - ook_bin << "01" if bit.to_s == '1'
                - ook_bin << "10" if bit.to_s == '0'
            - elsif type == "ook"
              -ook_bin << bin
          - else
            - if type == "pwm7525"
              -bin.scan(/./).each do |bit|
                - ook_bin << "1110" if bit.to_s == '1'
                - ook_bin << "1000" if bit.to_s == '0'
            - elsif type == "pwm"
              -bin.scan(/./).each do |bit|
                - ook_bin << "110" if bit.to_s == '1'
                - ook_bin << "100" if bit.to_s == '0'
            - elsif type == "manchester"
              -bin.scan(/./).each do |bit|
                - ook_bin << "10" if bit.to_s == '1'
                - ook_bin << "01" if bit.to_s == '0'
            - elsif type == "ook"
              -ook_bin << bin




          %p{:style=>" max-width:500px; word-wrap:break-word;"}= ook_bin
          %br
          %span="Size: "
          %span= ook_bin.size
          %span="bits "          


          %br
          %br
          %hr
          %h5 RFCat 
          =render "rfcat_config", device: device
          %p{:style=>" max-width:500px; word-wrap:break-word;"}= "d.RFxmit(\"#{Capture.to_hexcode ook_bin}\")" 
          %br
          %p="# or if you need to repeat the packet:"
          %p{:style=>" max-width:500px; word-wrap:break-word;"}= "d.RFxmit(\"\\x00\\x00\\x00\\x00#{Capture.to_hexcode ook_bin}\" * 5)" 



  %br




-#Vertical text style for TH
-#%th{:style => "color:grey;-webkit-transform: rotate(-90deg);-moz-transform: rotate(-90deg);-ms-transform: rotate(-90deg);-o-transform: rotate(-90deg);filter: progid:DXImageTransform.Microsoft.BasicImage(rotation=3);color: #FFF;text-transform: uppercase;"} 0